var testInputGraph = function(data){
	this.graphJson = data;
}
			
testInputGraph.prototype = {
	
	testNodesElement: function(node, index){
		if(typeof node.name == "undefined"){
			return "Missing name attribute in node "  + index;
		}
		
		if(typeof node.id  == "undefined"){
			return "Missing id attribute in node " + index;
		}
		return "";
	},
	
	testEdgesElement: function(edge, index){
		if(typeof edge.name == "undefined"){
			return "Missing name attribute in edges "  + index;
		}
		
		if(typeof edge.from == "undefined"){
			return "Missing from attribute in edges "  + index;
		}
		else{
			if(!this.isNodeExist(edge.from)){
				return "Not exist node_id in attribute \"from\" of edge "  + index;		
			}
		}
		
		if(typeof edge.to == "undefined"){
			return "Missing to attribute in edges "  + index;
		}
		else{
			if(!this.isNodeExist(edge.to)){
				return "Not exist node_id in attribute \"to\" of edge "  + index;	
			}
		}
		return "";
	},
	
	isNodeExist: function(nodeId){
		for(var i = 0; i < this.graphJson.nodes.length ; i++){
			if(nodeId == this.graphJson.nodes[i].id){
				return true;
			}
		}
		return false;
	},
	
	testNodes: function(listNodes){
		if(typeof this.graphJson.nodes == "undefined"){
			return "Missing nodes";
		}
		else{
			for(var i = 0; i < this.graphJson.nodes.length ; i++){
				return this.testNodesElement(this.graphJson.nodes[i], i + 1);	
			}
		}
		return "";
	},
	
	testEdges: function(listEdges){
		if(typeof this.graphJson.edges == "undefined"){
			return "";
		}
		else{
			for(var i = 0; i < this.graphJson.edges.length ; i++){
				return this.testEdgesElement(this.graphJson.edges[i], i + 1);	
			}
		}
		return "";
	},
	
	test: function(){
		if(typeof this.graphJson.name == "undefined"){
			alert("Missing graph name");
			return false;
		}
		else{
			var result = this.testNodes(this.graphJson.nodes);
			if(result != ""){
				alert(result);
				return false;
			}
			
			result = this.testEdges(this.graphJson.edges);
			if(result != ""){
				alert(result);
				return false;
			}
		}
		return true;
	}
	
	
}